package threadlocal;

import java.util.concurrent.TimeUnit;

/**
 * 改良版
 */
public class Mydemo0{
    private String content;
    ThreadLocal<String> threadLocal = new ThreadLocal<String>();
    public String getContent() {
        return threadLocal.get();
        // return content;
    }

    public void setContent(String content) {
        threadLocal.set(content);
        // this.content = content;
    }

    public static void main(String[] args) {
        final Mydemo01 mydemo01 = new Mydemo01();
        for (int i = 0; i < 6; i++) {
            Thread thread=new Thread(new Runnable() {
                public void run() {
                    mydemo01.setContent(Thread.currentThread().getName() + "的数据");
                    System.out.println("----------------------");
                    System.out.println(Thread.currentThread().getName()+"------>"+mydemo01.getContent());
                }
            });
            thread.setName("线程" + i);
            thread.start();
        }


    }

}
